home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / netlib / gettimeofday.c < prev    next >
C/C++ Source or Header  |  1994-03-28  |  4KB  |  116 lines

  1. RCS_ID_C="$Id: gettimeofday.c,v 1.2 1994/03/28 10:25:23 jraja Exp $"
  2. /*
  3.  * gettimeofday.c --- get time of the day
  4.  *
  5.  * Author: jraja <Jarno.Rajahalme@hut.fi>
  6.  *
  7.  * Copyright © 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
  8.  *                  Helsinki University of Technology, Finland.
  9.  *                  All rights reserved.
  10.  *
  11.  * Created      : Wed Sep 01 22:45:12 1993 jraja
  12.  * Last modified: Mon Mar 28 13:24:51 1994 jraja
  13.  *
  14.  * $Log: gettimeofday.c,v $
  15.  * Revision 1.2  1994/03/28  10:25:23  jraja
  16.  * Updated the autodoc.
  17.  *
  18.  * Revision 1.1  1993/10/18  06:23:47  jraja
  19.  * Initial revision
  20.  *
  21.  */
  22.  
  23. #include <sys/param.h>
  24. #include <sys/time.h>
  25.  
  26. /****** net.lib/gettimeofday *********************************************
  27.  
  28.     NAME   
  29.         gettimeofday - get date and time 
  30.  
  31.     SYNOPSIS
  32.         #include <sys/time.h>
  33.  
  34.         error = gettimeofday(tp, tzp)
  35.  
  36.         int gettimeofday(struct timeval *, struct timezone *)
  37.  
  38.     FUNCTION
  39.         The system's notion of the current Greenwich time and the
  40.         current time zone is obtained with the gettimeofday() call.
  41.         The time is expressed in seconds and microseconds since
  42.         midnight (0 hour), January 1, 1970.  The resolution of the
  43.         system clock is hardware dependent. If tzp is zero, the time
  44.         zone information will not be returned. Also, if your system
  45.         software is unable to provide time zone information, the
  46.         structure pointed by tzp will be filled with zeroes.
  47.    
  48.     PORTABILITY
  49.         UNIX
  50.  
  51.     INPUTS
  52.         The structures pointed to by tp and tzp are defined in
  53.         <sys/time.h> as:
  54.    
  55.              struct timeval {
  56.                   long tv_sec;      \* seconds since Jan. 1, 1970 *\
  57.                   long tv_usec;     \* and microseconds *\
  58.              };
  59.    
  60.              struct timezone {
  61.                   int  tz_minuteswest;   \* of Greenwich *\
  62.                   int  tz_dsttime;  \* type of dst correction to apply *\
  63.              };
  64.    
  65.         The timezone structure indicates the local time zone (meas-
  66.         ured in minutes of time westward from Greenwich), and a flag
  67.         that, if nonzero, indicates that Daylight Saving time
  68.         applies locally during the appropriate part of the year.
  69.  
  70.     RESULT
  71.         Returns 0 when successful and -1 with specific error code in 
  72.         errno in case of an error. No error codes are specified,
  73.         however.
  74.         
  75.     NOTES
  76.         gettimeofday() uses GetSysTime() function of the timer.device,
  77.         which is new to V36 of the device.
  78.  
  79.         Time zone information is taken from the locale.library, if it
  80.         is available (it is included in all Amiga systems from 2.1 and
  81.         up). Otherwise the environment variable "TZ" is consulted. If
  82.         it fails, the time zone is initialized to the GMT.
  83.  
  84.         Global variable TimerBase _must_ be initialized before
  85.         gettimeofday() is called. This is normally done automatically
  86.         by the autoinit module (timerinit.c) included in the net.lib.
  87.  
  88.     SEE ALSO
  89.         timer.device/GetSysTime()
  90. *****************************************************************************
  91. *
  92. */
  93.  
  94. /*
  95.  * See timerinit.c for comments on these
  96.  */
  97. extern struct timezone __time_zone;
  98. extern long __local_to_GMT;
  99.  
  100. int 
  101. gettimeofday(struct timeval *tp, struct timezone *tzp)
  102. {
  103.   if (tp) {
  104.     GetSysTime(tp);
  105.     tp->tv_sec += __local_to_GMT;
  106.   }
  107.   if (tzp) {
  108.     /*
  109.      * __time_zone is set up in the timerinit.c
  110.      */
  111.     *tzp = __time_zone;
  112.   }
  113.  
  114.   return 0;
  115. }
  116.